package com.publiccms.message;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.microprofile.websocket.handler.MessageHandler;
import org.microprofile.websocket.handler.Session;

public class WebsiteWebSocketHandler implements MessageHandler {
    protected final Log log = LogFactory.getLog(this.getClass());
    private Messagegate messageGate;

    public WebsiteWebSocketHandler(Messagegate messageGate) {
        this.messageGate = messageGate;
    }

    @Override
    public void onMessage(byte[] message, Session session) throws IOException {
        onMessage(new String(message), session);
    }

    @Override
    public void onMessage(String message, Session session) throws IOException {
        messageGate.sendToService(message);
    }

    @Override
    public void onOpen(Session session) throws IOException {
        log.info(session.getId() + "\t connected!");
    }

    @Override
    public void onClose(Session session) throws IOException {
        log.info(session.getId() + "\t closed!");
    }

}
